RAIS  3.2
C:/Projekte/RAIS/Specific Masks/EditDataRoles_New_Update3.aspx.cs
Go to the documentation of this file.
00001 
00027 using System;
00028 using System.Collections;
00029 using System.Configuration;
00030 using System.Data;
00031 using System.Linq;
00032 using System.Web;
00033 using System.Web.Security;
00034 using System.Web.UI;
00035 using System.Web.UI.HtmlControls;
00036 using System.Web.UI.WebControls;
00037 using System.Web.UI.WebControls.WebParts;
00038 using System.Xml.Linq;
00039 using RAIS.Common.UserManagement;
00040 using DataRoles = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.DataRole>;
00041 using FunctionRoleCategories = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.FunctionRole.Category>;
00042 using FunctionRoleSubcategories = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.FunctionRole.Subcategory>;
00043 using Masks = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.Mask>;
00044 using System.Collections.Generic;
00045 
00046 namespace RAIS.UI.SpecificMasks
00047 {
00048     public partial class EditDataRoles_New_Update3 : System.Web.UI.Page
00049     {
00050         #region ENUMS
00051         private enum FormMode
00052         {
00053             View,
00054             Add,
00055             Edit
00056         }
00057         #endregion
00058 
00059         #region PROPERTIES
00060 
00063         protected UserData CurrentUser
00064         {
00065             get { return (UserData)this.Session[UI.Common.Constants.CURRENT_USER_TAG]; }
00066         }
00070         private string SavedDataRoleSelection
00071         {
00072             get
00073             {
00074                 if (this.Session[RAIS.UI.Common.Constants.DATA_ROLE_SAVED_SELECTION_TAG] != null)
00075                     return this.Session[RAIS.UI.Common.Constants.DATA_ROLE_SAVED_SELECTION_TAG].ToString();
00076                 else
00077                     return string.Empty;
00078             }
00079             set
00080             {
00081                 this.Session[RAIS.UI.Common.Constants.DATA_ROLE_SAVED_SELECTION_TAG] = value;
00082             }
00083         }
00087         private DataRole SelectedRole
00088         {
00089             get
00090             {
00091                 DataRole dataRole = null;
00092 
00093                 if (this.LBdmrolename.SelectedIndex != -1)
00094                 {
00095                     DataRoles dataRoles = (DataRoles)this.Session[RAIS.UI.Common.Constants.DATA_ROLES_TAG];
00096                     if (dataRoles.ContainsKey(this.LBdmrolename.SelectedValue))
00097                         dataRole = dataRoles[this.LBdmrolename.SelectedValue];
00098                 }
00099 
00100                 return dataRole;
00101             }
00102         }
00106         protected bool ShowProtectors
00107         {
00108             get
00109             {
00110                 return UI.Common.PageManagement.GetShowProtectors(this);
00111             }
00112         }
00116         protected bool ShowEvaluators
00117         {
00118             get
00119             {
00120                 return UI.Common.PageManagement.GetShowEvaluators(this);
00121             }
00122         }
00126         private FunctionRole.Category SelectedCategory
00127         {
00128             get
00129             {
00130                 //FunctionRoleCategories categories = RAIS.ApplicationLogicLayer.UserManagement.FunctionalRoleCategories;
00131                 FunctionRoleCategories categories = UI.Common.TableManagement.GetFunctionRoleCategories(this, false);
00132                 if (categories != null && categories.ContainsKey(this.DDLcategory.SelectedValue))
00133                     return categories[this.DDLcategory.SelectedValue];
00134                 else
00135                     return null;
00136             }
00137         }
00141         private FunctionRole.Subcategory SelectedSubcategory
00142         {
00143             get
00144             {
00145                 if (this.SelectedCategory != null)
00146                 {
00147                     //FunctionRoleSubcategories subcategories = RAIS.ApplicationLogicLayer.UserManagement.GetFunctionalRoleSubcategories(this.SelectedCategory, false, false);
00148                     FunctionRoleSubcategories subcategories = UI.Common.TableManagement.GetFunctionRoleSubcategoriesByCategory(this, this.SelectedCategory, false, false, false);
00149                     if (subcategories != null && subcategories.ContainsKey(this.DDLsubcategory.SelectedValue))
00150                         return subcategories[this.DDLsubcategory.SelectedValue];
00151                     else
00152                         return null;
00153                 }
00154                 else
00155                     return null;
00156             }
00157         }
00161         private Mask SelectedMask
00162         {
00163             get
00164             {
00165                 if (this.SelectedCategory != null && this.SelectedSubcategory != null)
00166                 {
00167                     Masks masks = UI.Common.TableManagement.GetMasksByCategoryAndSubcategory(this, this.SelectedCategory, this.SelectedSubcategory, false);
00168                     if (masks != null && masks.ContainsKey(this.DDLmask.SelectedValue))
00169                         return masks[this.DDLmask.SelectedValue];
00170                     else
00171                         return null;
00172                 }
00173                 else
00174                     return null;
00175             }
00176         }
00180         private FormMode CurrentFormMode
00181         {
00182             get
00183             {
00184                 if (Session["DataRoleRestrictionsFormMode"] != null)
00185                     return (FormMode)Session["DataRoleRestrictionsFormMode"];
00186                 else return FormMode.View;
00187             }
00188         }
00192         private string SelectedRestrictionID
00193         {
00194             get
00195             {
00196                 if (GVrestrictions.SelectedRow != null)
00197                     return GVrestrictions.SelectedRow.Cells[0].Text;
00198                 else return null;
00199             }
00200         }
00201         #endregion
00202 
00203         #region EVENT HANDLER
00204 
00205         protected void Page_PreLoad(object sender, EventArgs e)
00206         {
00207             RAIS.UI.Common.PageManagement.TrimTextBoxValues(this);
00208         }
00209         
00210         protected void Page_Load(object sender, EventArgs e)
00211         {
00212             this.Response.Cache.SetNoStore();
00213             if (this.CurrentUser == null)
00214                 UI.Common.AccessManagement.SignOut(this);
00215 
00216             if (!this.IsPostBack)
00217             {
00218                 this.LBLadmin.ForeColor = RAIS.UI.Common.Constants.COLOR_OF_MENU_BAR_TEXT_HIGHLIGHT;
00219                 this.LBLusernameNoTranslation.Text = this.CurrentUser.Name;
00220                 UI.Common.UserManagement.InitializeDataRolesListBox(this.LBdmrolename, this.SavedDataRoleSelection);
00221 
00222                 UI.Common.Localisation.TranslateGridViewHeader(this.GVrestrictions, this.ToString(), RAIS.Common.Constants.DEFAULT_LANGUAGE, this.CurrentUser.Language);
00223 
00224                 UI.Common.PageManagement.InitializePage(this, this.TreeView1);
00225                 UI.Common.TableManagement.InitializeCategoryList(DDLcategory);
00226                 DDLcategory.Items.Insert(0, RAIS.ApplicationLogicLayer.Localisation.Translate(RAIS.UI.Common.Constants.DATA_ROLE_RESTRICTIONS_SELECT_ALL_TEXT, "ASP.editdataroles_new_update3_aspx", RAIS.Common.Constants.DEFAULT_LANGUAGE, this.CurrentUser.Language));
00227                 DDLcategory.SelectedIndex = 0;
00228 
00229                 Dictionary<string, RAIS.Common.TableManagement.Query> queries = UI.Common.TableManagement.GetQueries(this, true);
00230                 foreach (RAIS.Common.TableManagement.Query query in queries.Values)
00231                 {
00232                     if (query.Type == RAIS.Common.TableManagement.Query.QueryType.DataRoleRestriction)
00233                         DDLquery.Items.Add(query.Name);
00234                 }
00235 
00236                 string returnMessage = String.Empty;
00237                 GVrestrictions.DataSource = UI.Common.DataRoleRestrictionManagement.GetDataRoleRestrictions(this.SelectedRole, ref returnMessage, this.CurrentUser.Language);
00238                 GVrestrictions.DataBind();
00239                 GVrestrictions.Columns[0].Visible = false;
00240 
00241                 if (!String.IsNullOrEmpty(returnMessage))
00242                     RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00243                                                                         returnMessage,
00244                                                                         false);
00245                 OnSetFormMode(FormMode.View);
00246                 UI.Common.Localisation.TranslatePage(this);
00247             }
00248 
00249             Page.ClientScript.RegisterStartupScript(this.GetType(), "hideLBLprocessingScript", "document.getElementById('LBLprocessing').style.display = 'None';", true);
00250             UI.Common.PageManagement.InitHelpMainMenu(LBTNdefault);
00251         }
00252 
00253         protected void Page_Init(object sender, EventArgs e)
00254         {
00255             Common.PageManagement.SetScrolableListBox(this.LBdmrolename, this, true);
00256         }
00257 
00258         protected void LBTNlogout_Click(object sender, EventArgs e)
00259         {
00260             UI.Common.AccessManagement.SignOut(this);
00261         }
00262 
00263         protected void BTNadd_Click(object sender, EventArgs e)
00264         {
00265             OnSetFormMode(FormMode.Add);
00266         }
00267 
00268         protected void BTNedit_Click(object sender, EventArgs e)
00269         {
00270             OnSetFormMode(FormMode.Edit);
00271             OnSetEditControls();
00272         }
00273 
00274         protected void BTNdelete_Click(object sender, EventArgs e)
00275         {
00276             if (GVrestrictions.SelectedRow != null)
00277             {
00278                 string returnMessage = String.Empty;
00279                 bool success = UI.Common.DataRoleRestrictionManagement.DeleteDataRoleRestriction(this.SelectedRestrictionID, ref returnMessage);
00280                 if (success)
00281                     OnSetFormMode(FormMode.View);
00282                 else
00283                     RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00284                                                                         returnMessage,
00285                                                                         false);
00286             }
00287         }
00288 
00289         protected void BTNdiscard_Click(object sender, EventArgs e)
00290         {
00291             OnSetFormMode(FormMode.View);
00292         }
00293 
00294         protected void BTNapply_Click(object sender, EventArgs e)
00295         {
00296             if (!TBXrestriction.Text.Equals(String.Empty) && DDLquery.Items.Count > 0)
00297             {
00298                 if (!RestrictionAlreadyExisting(TBXrestriction.Text))
00299                 {
00300                     string categoryID = "NULL";
00301                     if (this.SelectedCategory != null)
00302                         categoryID = this.SelectedCategory.ID.ToString();
00303 
00304                     string subcategoryID = "NULL";
00305                     if (this.SelectedSubcategory != null)
00306                         subcategoryID = this.SelectedSubcategory.ID.ToString();
00307 
00308                     string maskID = "NULL";
00309                     if (this.SelectedMask != null)
00310                         maskID = this.SelectedMask.ID.ToString();
00311 
00312                     string returnMessage = String.Empty;
00313                     bool success = true;
00314                     if (this.CurrentFormMode == FormMode.Add)
00315                         success = UI.Common.DataRoleRestrictionManagement.AddDataRoleRestriction(TBXrestriction.Text, DDLquery.SelectedItem.Text, this.SelectedRole.ID.ToString(), categoryID, subcategoryID, maskID, ref returnMessage);
00316                     else
00317                         success = UI.Common.DataRoleRestrictionManagement.EditDataRoleRestriction(this.SelectedRestrictionID, TBXrestriction.Text, DDLquery.SelectedItem.Text, this.SelectedRole.ID.ToString(), categoryID, subcategoryID, maskID, ref returnMessage);
00318 
00319                     if (success)
00320                         OnSetFormMode(FormMode.View);
00321                     else
00322                         RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00323                                                                         returnMessage,
00324                                                                         false);
00325                 }
00326                 else
00327                     RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00328                                                                     "Restriction name already exists for this data role.",
00329                                                                     false);
00330             }
00331             else
00332                 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00333                                                                 "Please select the necessary data.",
00334                                                                 false);
00335         }
00336 
00337         protected void LBdmrolename_SelectedIndexChanged(object sender, EventArgs e)
00338         {
00339             string returnMessage = String.Empty;
00340             GVrestrictions.Columns[0].Visible = true;
00341             GVrestrictions.DataSource = UI.Common.DataRoleRestrictionManagement.GetDataRoleRestrictions(this.SelectedRole, ref returnMessage, this.CurrentUser.Language);
00342             GVrestrictions.DataBind();
00343             GVrestrictions.Columns[0].Visible = false;
00344             OnSetFormMode(FormMode.View);
00345 
00346             if (!String.IsNullOrEmpty(returnMessage))
00347                 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00348                                                                         returnMessage,
00349                                                                         false);
00350         }
00351 
00352         protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
00353         {
00354             UI.Common.UserManagement.ProcessTreeViewOnRedirect(this.TreeView1);
00355         }
00356 
00357         protected void DDLcategory_SelectedIndexChanged(object sender, EventArgs e)
00358         {
00359             if (DDLcategory.SelectedIndex != 0)
00360             {
00361                 this.OnSetCategoryValue();
00362                 DDLsubcategory.Visible = true;
00363                 LBLsubcategory.Visible = true;
00364                 DDLmask.Visible = false;
00365                 LBLmask.Visible = false;
00366             }
00367             else
00368             {
00369                 DDLsubcategory.Visible = false;
00370                 LBLsubcategory.Visible = false;
00371                 DDLmask.Visible = false;
00372                 LBLmask.Visible = false;
00373                 DDLsubcategory.SelectedIndex = 0;
00374                 DDLmask.SelectedIndex = 0;
00375             }
00376         }
00377 
00378         protected void DDLsubcategory_SelectedIndexChanged(object sender, EventArgs e)
00379         {
00380             if (DDLsubcategory.SelectedIndex != 0)
00381             {
00382                 this.OnSetSubcategoryValue();
00383                 DDLmask.Visible = true;
00384                 LBLmask.Visible = true;
00385             }
00386             else
00387             {
00388                 DDLmask.Visible = false;
00389                 LBLmask.Visible = false;
00390                 DDLmask.SelectedIndex = 0;
00391             }
00392         }
00393 
00394         protected void GVrestrictions_SelectedIndexChanged(object sender, EventArgs e)
00395         {
00396             if (GVrestrictions.SelectedRow != null)
00397             {
00398                 BTNedit.Enabled = true;
00399                 BTNdelete.Enabled = true;
00400                 BTNcompile.Enabled = true;
00401             }
00402             else
00403             {
00404                 BTNedit.Enabled = false;
00405                 BTNdelete.Enabled = false;
00406                 BTNcompile.Enabled = false;
00407             }
00408         }
00409 
00410         protected void BTNcompile_Click(object sender, EventArgs e)
00411         {
00412             //Session["CompileDataRoleRestriction"] = true;
00413             //BTNadd.Enabled = false;
00414             //BTNedit.Enabled = false;
00415             //BTNdelete.Enabled = false;
00416             //BTNcompile.Enabled = false;
00417             LBLresult.Text = "Processing...";
00418 
00419             this.OnSetEditControls();
00420             string param = String.Empty;
00421             if (this.SelectedCategory != null)
00422             {
00423                 param += "&selectedCategoryID=" + this.SelectedCategory.ID;
00424                 if (this.SelectedSubcategory != null)
00425                 {
00426                     param += "&selectedSubcategoryID=" + this.SelectedSubcategory.ID;
00427                     if (this.SelectedMask != null)
00428                         param += "&selectedMaskID=" + this.SelectedMask.ID;
00429                 }
00430             }
00431             Response.Redirect("EditDataRoles_New_Update4.aspx?restrictionID=" + this.SelectedRestrictionID + param);
00432         }
00433 
00434         #endregion
00435 
00436         #region PRIVATE HELPER METHODS
00437 
00438         private void OnSetFormMode(FormMode formMode)
00439         {
00440             Session["DataRoleRestrictionsFormMode"] = formMode;
00441             switch (formMode)
00442             {
00443                 case FormMode.View:
00444                     LBLresult.Text = String.Empty;
00445                     LBdmrolename.Enabled = true;
00446                     GVrestrictions.Enabled = true;
00447                     FSattributes.Visible = false;
00448                     BTNadd.Enabled = true;
00449                     BTNedit.Enabled = false;
00450                     BTNdelete.Enabled = false;
00451                     BTNdiscard.Enabled = false;
00452                     BTNsave.Enabled = false;
00453                     BTNcompile.Enabled = false;
00454                     string returnMessage = String.Empty;
00455                     GVrestrictions.Columns[0].Visible = true;
00456                     GVrestrictions.DataSource = UI.Common.DataRoleRestrictionManagement.GetDataRoleRestrictions(this.SelectedRole, ref returnMessage, this.CurrentUser.Language);
00457                     GVrestrictions.DataBind();
00458                     GVrestrictions.Columns[0].Visible = false;
00459                     GVrestrictions.SelectedIndex = -1;
00460                     if (!String.IsNullOrEmpty(returnMessage))
00461                         RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00462                                                                         returnMessage,
00463                                                                         false);
00464                     break;
00465                 case FormMode.Add:
00466                     LBdmrolename.Enabled = false;
00467                     GVrestrictions.Enabled = false;
00468                     FSattributes.Visible = true;
00469                     BTNadd.Enabled = false;
00470                     BTNedit.Enabled = false;
00471                     BTNdelete.Enabled = false;
00472                     BTNdiscard.Enabled = true;
00473                     BTNsave.Enabled = true;
00474                     GVrestrictions.SelectedIndex = -1;
00475                     TBXrestriction.Text = String.Empty;
00476                     if (DDLquery.Items.Count > 0)
00477                         DDLquery.SelectedIndex = 0;
00478                     DDLcategory.SelectedIndex = 0;
00479                     DDLsubcategory.SelectedIndex = 0;
00480                     DDLmask.SelectedIndex = 0;
00481                     DDLsubcategory.Visible = false;
00482                     LBLsubcategory.Visible = false;
00483                     DDLmask.Visible = false;
00484                     LBLmask.Visible = false;
00485                     BTNcompile.Enabled = false;
00486                     break;
00487                 case FormMode.Edit:
00488                     LBdmrolename.Enabled = false;
00489                     GVrestrictions.Enabled = false;
00490                     FSattributes.Visible = true;
00491                     BTNadd.Enabled = false;
00492                     BTNedit.Enabled = false;
00493                     BTNdelete.Enabled = false;
00494                     BTNdiscard.Enabled = true;
00495                     BTNsave.Enabled = true;
00496                     BTNcompile.Enabled = false;
00497                     break;
00498             }
00499         }
00500 
00501         private void OnSetCategoryValue()
00502         {
00503             UI.Common.TableManagement.InitializeSubcategoryListByCategory(
00504                   this.DDLsubcategory
00505                 , this.SelectedCategory
00506                 , this.ShowProtectors
00507                 , this.ShowEvaluators);
00508             this.DDLsubcategory.Items.Insert(0, RAIS.ApplicationLogicLayer.Localisation.Translate(RAIS.UI.Common.Constants.DATA_ROLE_RESTRICTIONS_SELECT_ALL_TEXT, "ASP.editdataroles_new_update3_aspx", RAIS.Common.Constants.DEFAULT_LANGUAGE, this.CurrentUser.Language));
00509             this.DDLsubcategory.SelectedIndex = 0;
00510         }
00511 
00512         private void OnSetSubcategoryValue()
00513         {
00514             UI.Common.TableManagement.InitializeMaskListByCategoryAndSubcategory(
00515                   this.DDLmask
00516                 , this.SelectedCategory
00517                 , this.SelectedSubcategory);
00518             this.DDLmask.Items.Insert(0, RAIS.ApplicationLogicLayer.Localisation.Translate(RAIS.UI.Common.Constants.DATA_ROLE_RESTRICTIONS_SELECT_ALL_TEXT, "ASP.editdataroles_new_update3_aspx", RAIS.Common.Constants.DEFAULT_LANGUAGE, this.CurrentUser.Language));
00519             this.DDLmask.SelectedIndex = 0;
00520         }
00521 
00522         private void OnSetEditControls()
00523         {
00524             if (GVrestrictions.SelectedRow != null)
00525             {
00526                 string restrictionID = this.SelectedRestrictionID;
00527                 string returnMessage = String.Empty;
00528                 DataRow row = UI.Common.DataRoleRestrictionManagement.GetDataRoleRestriction(restrictionID, ref returnMessage);
00529 
00530                 if (!String.IsNullOrEmpty(returnMessage))
00531                     RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00532                                                                         returnMessage,
00533                                                                         false);
00534 
00535                 TBXrestriction.Text = row["Restriction Name"].ToString();
00536                 DDLquery.SelectedIndex = DDLquery.Items.IndexOf(DDLquery.Items.FindByText(row["Query Name"].ToString()));
00537 
00538                 ListItem category = DDLcategory.Items.FindByText(row["Category Name"].ToString());
00539                 if (category != null)
00540                 {
00541                     DDLcategory.SelectedIndex = DDLcategory.Items.IndexOf(category);
00542                     OnSetCategoryValue();
00543                     ListItem subcategory = DDLsubcategory.Items.FindByText(row["Subcategory Name"].ToString());
00544                     if (subcategory != null)
00545                     {
00546                         DDLsubcategory.SelectedIndex = DDLsubcategory.Items.IndexOf(subcategory);
00547                         OnSetSubcategoryValue();
00548                         ListItem mask = DDLmask.Items.FindByText(row["Mask Name"].ToString());
00549                         if (mask != null)
00550                         {
00551                             DDLmask.SelectedIndex = DDLmask.Items.IndexOf(mask);
00552                         }
00553                         else
00554                             DDLmask.SelectedIndex = 0;
00555                         DDLmask.Visible = true;
00556                         LBLmask.Visible = true;
00557                     }
00558                     else
00559                     {
00560                         DDLsubcategory.SelectedIndex = 0;
00561                         DDLmask.Visible = false;
00562                         LBLmask.Visible = false;
00563                     }
00564                     DDLsubcategory.Visible = true;
00565                     LBLsubcategory.Visible = true;
00566                 }
00567                 else
00568                 {
00569                     DDLcategory.SelectedIndex = 0;
00570                     DDLsubcategory.Visible = false;
00571                     DDLmask.Visible = false;
00572                     LBLsubcategory.Visible = false;
00573                     LBLmask.Visible = false;
00574                 }
00575             }
00576         }
00577 
00578         private bool RestrictionAlreadyExisting(string restrictionName)
00579         {
00580             string returnMessage = String.Empty;
00581             DataTable dt = UI.Common.DataRoleRestrictionManagement.GetDataRoleRestrictions(this.SelectedRole, ref returnMessage, this.CurrentUser.Language);
00582             if (!String.IsNullOrEmpty(returnMessage))
00583                 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00584                                                                         returnMessage,
00585                                                                         false);
00586             foreach (DataRow row in dt.Rows)
00587             {
00588                 string text = row[1].ToString();
00589                 if (this.CurrentFormMode == FormMode.Edit && !row[0].ToString().Equals(this.SelectedRestrictionID) && row[1].ToString().Equals(restrictionName))
00590                     return true;
00591                 else if (this.CurrentFormMode != FormMode.Edit && row[1].ToString().Equals(restrictionName))
00592                     return true;
00593             }
00594             return false;
00595         }
00596 
00597         #endregion
00598     }
00599 }